require('./header.css')

var _common_util = require('util/common_util.js');

var header = {
    init : function(){
        this.onLoad();
        this.bindEvent();
    },
    onLoad : function(){
        document.getElementById('logo').href = _common_util.getFrontURL('');
        var keyword = _common_util.getURLParam('keyword');
        if(keyword){
            $('#search-input').val(keyword);
        }
    },
    bindEvent : function(){
        var _this = this;
        $('#search-btn').click(function(){
            _this.searchSubmit();
        });
        $('#search-input').keyup(function(e){
            if(e.keyCode == 13){
                _this.searchSubmit();
            }
        });
    },
    searchSubmit : function(){
        var keyword = $.trim($('#search-input').val());
        if(keyword){
            // window.location.href  = "./view/list.html?keyword=" + keyword;
            window.location.href  = _common_util.getFrontURL('list.html?keyword=') + "" + keyword;
        }else{
            _common_util.goHome();
        }
    }
};

header.init();